<script type="text/javascript">
    $(document).ready(function(){
        $('#form_new_product').dialog({
            'title': 'Thêm sản phẩm mới',
            'autoOpen':false,
            'width':1000,
            'height':600,
            'resizable':false,
            'modal':true,
            'dialogClass':'fixed-dialog',
        });
        $('#form_new_product').dialog('open');
        $('#show_form_new_product').click(function(){
            $('#form_new_product').dialog('open');
        });
    });
</script>
<div class="admin_header_title">ADD NEW PRODUCT FROM URL</div>
<?php 
    if(isset($_POST['is_add_product']))
    {
        if($template->get('new_product_uri'))
        {
            echo '<div class="metro_message_susscess"><a href="'.URL::getLink('product/id/'.$template->get('new_product_uri')).'"><i class="fa fa-check"></i> New product '.URL::getLink('product/id/'.$template->get('new_product_uri')).'</a></div>';
        }
    }
    if($template->get('bIsExist'))
    {
        echo '<div class="metro_message_error"><i class="fa fa-exclamation-triangle"></i> Link is ready exist!</div>';
    }
?>

<div>
    <form action="" method="POST">
        <div>
            <input type="text" disabled value="URL" style="width: 100px;margin-right: -10px;">
            <input type="text" name="url" style="width: 426px;" value="<?php if(!isset($_POST['is_add_product'])){ echo (isset($_POST['url']) ? $_POST['url'] : '');} ?>">
        </div>
        <div style="margin-top:10px;">
            <input type="text" disabled value="Provider" style="width: 100px;margin-right: -10px;">
            <?php
                $aParamProvider = array(
                    'width' => '400px',
                    'id' =>'tb_provider',
                    'aValue' => DBObject::getProviders(),
                    'stringTitle' => 'provider_name',
                    'stringKey' => 'id',
                );
                includeBlock('block/customComboboxBlock',$aParamProvider);
            ?>
        </div>

        <div style="margin-top:10px;width: 567px;text-align: right;">
            <button type="submit" class="flat_metro_button green_metro_style">Add product <i class="fa fa-plus"></i></button>
            <?php if(!isset($_POST['is_add_product']) && isset($_POST['url']) && !$template->get('bIsExist')){ ?>
                <button type="button" id="show_form_new_product" class="flat_metro_button violet_metro_style">Show <i class="fa fa-th"></i></button>
                <?php } ?>
        </div>
    </form>
</div>


<?php if(!isset($_POST['is_add_product']) && isset($_POST['url']) && !$template->get('bIsExist')){?>
    <div id="form_new_product">
        <h2 id="successfull_message" style="display: none;" class="title green_style">ĐĂNG SẢN PHẨM THÀNH CÔNG!</h2>
        <form action="" method="POST" enctype="multipart/form-data">
            <input type="hidden" name="is_add_product" value="1">
            <input type="hidden" name="url" value="<?php echo $_POST['url']; ?>">
            <div class="left_product_content">
                <?php if($template->get('aImages')){foreach($template->get('aImages') as $img){ ?>
                    <div class="dangspdivimg">
                        <img class="image_preview" src="<?php echo URL::getLink('upload/'.$img); ?>" alt="">
                        <input type="hidden" name="avatar[]" class="bt_choice_image dangspinputfile" value="<?php echo $img; ?>">
                    </div>
                    <?php }} ?>
            </div>
            <div class="right_product_content">
                <div class="dangsptitle">
                    <div style="margin-left: 20px;">
                        <div>
                            <p>Tiêu  Đề</p>
                            <p><input type="text" name="tensp" value="<?php echo ($template->get('title') ? $template->get('title') : ''); ?>" style="width: 525px;"></p>
                        </div>
                        <div>
                            <p>Nhà Sản Xuất</p>
                            <?php
                                $aParamLocation = array(
                                    'width' => '500px',
                                    'id' =>'dm_name',
                                    'aValue' => DBObject::getManufacturers(),
                                    'stringTitle' => 'name',
                                    'stringKey' => 'uri',
                                    'title' => isset($template->get('aSettings')['default_menufacturer_add_product']) ? $template->get('aSettings')['default_menufacturer_add_product']['setting_value'] : '',
                                    'value' => isset($template->get('aSettings')['default_menufacturer_add_product']) ? $template->get('aSettings')['default_menufacturer_add_product']['setting_key'] : '',
                                );
                                includeBlock('block/customComboboxBlock',$aParamLocation);
                            ?>
                            <p>Đơn Giá</p>
                            <p><input value="<?php echo ($template->get('title') ? $template->get('price') : ''); ?>" type="text" name="dongia" style="width:525px;"></p>
                            <p> Địa Điểm :
                                <?php
                                    $aParamLocation = array(
                                        'width' => '500px',
                                        'id' =>'location_id',
                                        'aValue' => DBObject::getLocations(),
                                        'stringTitle' => 'name',
                                        'stringKey' => 'name',
                                        'title' => isset($template->get('aSettings')['default_location_add_product']) ? $template->get('aSettings')['default_location_add_product']['setting_value'] : '',
                                        'value' => isset($template->get('aSettings')['default_location_add_product']) ? $template->get('aSettings')['default_location_add_product']['setting_key'] : '',
                                    );
                                    includeBlock('block/customComboboxBlock',$aParamLocation);
                                ?>
                            </p>
                            <p>Danh Mục</p>
                            <?php
                                $aParams = array(
                                    'width' => '500px',
                                    'category_name' => $template->get('oProvider')->category_name ,
                                    'category_uri' => $template->get('oProvider')->category_uri,
                                    'list_categories' => $template->get('oProvider')->categories_uri,
                                );
                                includeBlock('block/categoryBlock' , $aParams);
                            ?>
                        </div>
                        <div> 
                            <p>Mô tả chi tiết</p>
                            <textarea class="" id="summary" name="description" cols="20" rows="20" style="width: 540px;" ><?php echo ($template->get('title') ? $template->get('description') : ''); ?></textarea>
                        </div>
                    </div>
                    <div style="text-align: right;margin-bottom:10px;clear: both;">
                        <input type="text" hidden="true" name="title">
                        <button type="submit dangspbutton" class="flat_metro_button green_metro_style">Đăng sản phẩm<i class="fa fa-plus"></i></button>
                    </div>
                </div>
            </div>
            <div style="clear: both;"></div>
        </form>
    </div>
    <?php } ?>